package com.gh.elm.model;

import java.util.Scanner;

/*
 * 系统类
 */
public class Sys {
	private Scanner scan = new Scanner(System.in);
	private User[] users = new User[2];
	private Menu[] menus = new Menu[5];
	private Order[] orders = new Order[4];
	public Sys(){
		
		//初始化用户
		//1、创建普通用户；
		User binbin = new User("binbin","123",2);
		//2、创建商家用户；
		User root = new User("root","123",1);
		//存放在用户数组里；
		users[0] = binbin;
		users[1] = root;
		
		//初始化菜单；
		Menu menu1 = new Menu("酸菜鱼",38,0);
		Menu menu2 = new Menu("龙虾",128,0);
		Menu menu3 = new Menu("啤酒鸭",58,0);
		menus[0] = menu1;
		menus[1] = menu2;
		menus[2] = menu3;
	}
	
	//显示登录菜单；
	public boolean showLoginMenu(){
		System.out.println("***欢迎使用饿了么订餐系统***");
		System.out.println("请选择登录角色： 1、商家    2、客户");
		User user = new User();
		int role = user.inputRole();
		System.out.println("请用户输入账号和密码：");
		User iuser = user.inputUser(role);//返回用户输入的账号和密码（user对象）
		return checkUser(iuser);
	
	}
	//显示主菜单
	public int shoMenu(){
		System.out.println("1、订餐");
		System.out.println("2、查询订单");
		System.out.println("3、签收订单");
		System.out.println("4、删除订单");
		System.out.println("5、点赞");
		System.out.println("6、退出");
		User user = new User();
		return user.inputService();
	}
	
	//验证账户是否存在；
	public boolean checkUser(User user){
		for (int i = 0; i < users.length; i++) {
			if (user.getUsernamwe().equals(users[i].getUsernamwe())&&user.getPass().equals(users[i].getPass())&&user.getRole() == users[i].getRole()) {
				System.out.println("验证通过！");
				return true;
			}
		}
		System.out.println("账号或者密码错误！");
		return false;
	}
	
	//改变订单状态  （签收订单）
		//用户选择订单
	public void changeOrder(){
		System.out.println("请输入要签收的 订单序号：");
		User user  = new User();
		int num =user.inputMenu();
		orders[num-1].setStates(1);
		for (int i = 0; i < orders.length; i++) {
			if (orders[i] != null) {
				System.out.println((i+1)+"\t"+orders[i].getFoodName()+"\t"+orders[i].getFoodNum()+"\t"+orders[i].getMoney()+"\t"+orders[i].getUname()+"\t"+orders[i].getOdate()+"\t"+orders[i].getAddress()+"\t"+orders[i].getStates());
			}
		}
		System.out.println("签收完成");
	}
	//删除订单
	public void deleteOrder(){
		System.out.println("请输入要签收的 订单序号：");
		User user  = new User();
	
		int num = user.inputMenu();
		orders[num-1]= null;
		for (int i = 0; i < orders.length; i++) {
			if (orders[i] != null) {
				System.out.println((i+1)+"\t"+orders[i].getFoodName()+"\t"+orders[i].getFoodNum()+"\t"+orders[i].getMoney()+"\t"+orders[i].getUname()+"\t"+orders[i].getOdate()+"\t"+orders[i].getAddress()+"\t"+orders[i].getStates());
			}
		}
		System.out.println("删除完成");
	
	}
	//用户选择要点赞的菜品序号并进行点赞；
	public void giveOrder(){
		System.out.println("请输入要点赞的 菜品序号：");
		User user  = new User();
		int num = user.inputMenu();
	
		//for (int i = 0; i < menus.length; i++) {
			int give = menus[num-1].getGive();
			menus[num-1].setGive(++give);
			System.out.println("点赞完成");
		//	break;
		//}
		
	
	}
	
	
	
	public Scanner getScan() {
		return scan;
	}
	public void setScan(Scanner scan) {
		this.scan = scan;
	}
	public User[] getUsers() {
		return users;
	}
	public void setUsers(User[] users) {
		this.users = users;
	}
	public Menu[] getMenus() {
		return menus;
	}
	public void setMenus(Menu[] menus) {
		this.menus = menus;
	}
	public Order[] getOrders() {
		return orders;
	}
	public void setOrders(Order[] orders) {
		this.orders = orders;
	} 

}
